package homeWork.day01_5_14;
import java.util.Random;
import java.util.Scanner;
public class Test06 {
	public static void main(String[] args) {
		String line = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";//验证码
		String code="";//验证码
		Random ran=new Random();//随机数
		int x;
		System.out.println("验证码为:");
		for(int i=0;i<4;i++){//循环4次
			x=ran.nextInt(line.length());//随机数
			char c=line.charAt(x);//随机数
			code=code+c;//拼接
			System.out.print(c);//输出
		}
		System.out.println();
		panduan(code);//调用puanduan方法
	}
	public static void panduan(String code){
		Scanner scan=new Scanner(System.in);//输入
		boolean flag1=true;
		while(flag1){
			System.out.println("请输入验证码:");
			String input = scan.nextLine();
			boolean flag=input.equalsIgnoreCase(code);//忽略大小写判断input和code是否相等
			if(flag){
				System.out.println("验证码正确!");//input和code相等，输出验证码正确
				flag1=false;//跳出while死循环
			}else {
				System.out.println("验证码错误!");//input和code不相等，输出验证码错误
			}
		}
	}
}






